package edu.wpi.first.wpilibj.team1662;

import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.buttons.Button;
import edu.wpi.first.wpilibj.buttons.JoystickButton;
import edu.wpi.first.wpilibj.team1662.commands.LaunchBall;
import edu.wpi.first.wpilibj.team1662.commands.PickUp;
import edu.wpi.first.wpilibj.team1662.commands.ShiftUp;
import edu.wpi.first.wpilibj.team1662.commands.auto.Reverse;

/**
 * This class is the glue that binds the controls on the physical operator
 * interface to the commands and command groups that allow control of the robot.
 */
public class OI {
    //// CREATING BUTTONS
    // One type of button is a joystick button which is any button on a joystick.
    // You create one by telling it which joystick it's on and which button
    // number it is.
    // Joystick stick = new Joystick(port);
    // Button button = new JoystickButton(stick, buttonNumber);

    // Another type of button you can create is a DigitalIOButton, which is
    // a button or switch hooked up to the cypress module. These are useful if
    // you want to build a customized operator interface.
    // Button button = new DigitalIOButton(1);
    // There are a few additional built in buttons you can use. Additionally,
    // by subclassing Button you can create custom triggers and bind those to
    // commands the same as any other Button.
    //// TRIGGERING COMMANDS WITH BUTTONS
    // Once you have a button, it's trivial to bind it to a button in one of
    // three ways:
    // Start the command when the button is pressed and let it run the command
    // until it is finished as determined by it's isFinished method.
    // button.whenPressed(new ExampleCommand());
    // Run the command while the button is being held down and interrupt it once
    // the button is released.
    // button.whileHeld(new ExampleCommand());
    // Start the command when the button is released  and let it run the command
    // until it is 9finished as determined by it's isFinished method.
    // button.whenReleased(new ExampleCommand());
    //Random comment
    //Random comment and stuff!
    private Joystick driver = new Joystick(RobotMap.drivePad);
    private Joystick manipulator = new Joystick(RobotMap.manipulator);
    private Button shift = new JoystickButton(driver, RobotMap.shift);
    private Button low = new JoystickButton(manipulator, 1);
    private Button mid1 = new JoystickButton(manipulator, 2);
    private Button mid2 = new JoystickButton(manipulator, 3);
    private Button high = new JoystickButton(manipulator, 4);
    private Button raiseArm = new JoystickButton(manipulator, RobotMap.pickUp);
    private Button launch = new JoystickButton(manipulator, RobotMap.launch);

     public OI() {
        shift.toggleWhenPressed(new ShiftUp());
        launch.toggleWhenPressed(new LaunchBall());
        raiseArm.toggleWhenPressed(new PickUp());
    }
    public double getPickupThrottle() {
        if(manipulator.getRawAxis(5) < .2 && manipulator.getRawAxis(5) > -.2)
            return 0;
        else
            return manipulator.getRawAxis(5);
    }
    public double getRightStick() {
        return driver.getRawAxis(2);
    //switch numbers above.
    }
    public double getLeftStick() {
        return driver.getRawAxis(5);
        //switched the numbers above.
        //keep numerals the same
    }
    public double getConveyorThrottle() {
        if(manipulator.getRawAxis(3) > .2 || manipulator.getRawAxis(3) < -.2)
            return Math.abs(manipulator.getRawAxis(3));
        else
            return 0;
    }
    public void updateButton(){
        if(low.get() == true)
            RobotMap.tripNum = 1;
        else if(mid1.get() == true)
            RobotMap.tripNum = 2;
        else if(mid2.get() == true)
            RobotMap.tripNum = 3;
        else if(high.get() == true)
            RobotMap.tripNum = 4;
    
    }
}